<template>
  <div class="container">
    <el-dialog
      title="题目审查核"
      :visible="dialogshenhe"
      width="30%"
      @close="close"
    >
      <el-form :model="formBase" ref="formBase" :rules="rules">
        <el-form-item>
          <el-row v-model="formBase.chkState">
            <el-col :span="6">
              <el-radio v-model="selectedSize" label="small">通过</el-radio>
            </el-col>
            <el-col :span="6">
              <el-radio v-model="selectedSize" label="medium">拒绝</el-radio>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item prop="chkRemarks">
          <el-row>
            <el-input
              type="textarea"
              placeholder="请输入审核意见"
              v-model="formBase.chkRemarks"
            ></el-input>
          </el-row>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-row type="flex" justify="end">
          <el-button @click="close">取 消</el-button>
          <el-button type="primary" @click="btnok">确 定</el-button>
        </el-row>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  props: {
    dialogshenhe: {
      type: Boolean,
      default: false
    },
    formBase: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      // 审核单选框，默认
      selectedSize: 'small',
      rules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    close() {
      this.$emit('update:dialogshenhe', false)
    },
    btnok() {
      this.$refs.formBase.validate(async isOK => {
        if (isOK) {
          if (this.selectedSize === 'small') {
            this.formBase.chkState = 1
          } else if (this.selectedSize === 'medium') {
            this.formBase.chkState = 2
          }
          if (this.formBase.chkState === 1 || this.formBase.chkState === 2) {
            await choiceCheck(this.formBase)
            this.$message.success('操作成功')
            console.log(this.formBase)
          }
          this.$emit('choice')
          this.close()
        }
      })
    }
  }
}
</script>

<style scoped lang='less'></style>
